package com.eatme.web.app.coupon.common.constant;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 分发目标
 */
public enum DistributeTarget {

    SINGLE("单用户",1),
    MULTI("多用户",2);

    /**
     * 分发目标描述
     */
    private String description;

    /**
     * 分发目标编码
     */
    private Integer code;

    DistributeTarget(String description, Integer code) {
        this.description = description;
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public Integer getCode() {
        return code;
    }

    public static DistributeTarget of(Integer code) {

        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny().
                orElseThrow(() -> new IllegalArgumentException(code + "not exists!"));
    }
}
